<{extend name="base" /}>
    <{block name="body" }>
        <style>html{font-size: 100px}</style>
        <div class="layui-body ">
            <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title">
                    <li class=""><a href="<{:url('admin/baidu/index')}>">已添加列表</a></li>
                    <li class=""><a href="<{:url('admin/baidu/create',['style_id'=>1])}>">样式一</a></li>
                    <li class=""><a href="<{:url('admin/baidu/create',['style_id'=>2])}>">样式二</a></li>
                    <li class=""><a href="<{:url('admin/baidu/create',['style_id'=>3])}>">样式三</a></li>
                    <li class=""><a href="<{:url('admin/baidu/create',['style_id'=>4])}>">样式四</a></li>
                    <li class="layui-this"><a href="<{:url('admin/baidu/create',['style_id'=>5])}>">样式五</a></li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show" id="app">
                        <div class="left">
                            <form class="layui-form" method="post" action="<{:url('admin/baidu/save')}>">
                                <input type="hidden" name="style" value="5">
                                <{php}>
                                if(request()->action() == 'edit'){
                                    echo '<input type="hidden" name="type" value="edit">';
                                    echo '<input type="hidden" name="id" value="'.request()->get('id').'">';
                                }
                                <{/php}>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">标题</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="content[title]" lay-verify="required" v-model='title' placeholder="{用此符号可飘红，支持多个} 必须成对书写"
                                            class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">缩略图</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="content[thumb]" lay-verify="required" v-model='thumb' class="layui-input layui-input-inline" id="mythumb">
                                        <input type="file" name="file" class="layui-upload-file">
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">描述</label>
                                    <div class="layui-input-block">
                                        <textarea name="content[desc]" lay-verify="required"  placeholder="{西宁长海医院}正规吗 西宁长海医院，医保{医院}，妇科检查28元，内分泌筛查套餐120元，医保定点，咨询热线"
                                            class="layui-textarea" v-model='desc'></textarea>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">链接</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="content[url]" v-model='url'  lay-verify="required|url" placeholder="例如：http://baidu.com" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">域名</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="content[host]" v-model='host' lay-verify="required" placeholder="例如：m.baidu.com" class="layui-input">
                                    </div>
                                </div>

                                <div class="group-item" >
                                        <div class="layui-form-item" v-for="(item,index) in groupItems">
                                            <label class="layui-form-label">标题组</label>
                                            <div class="layui-input-block">
                                                <input type="text" :name="'content[groupItems]['+index+'][title]'" v-model='item.title' lay-verify="required" placeholder="特色服务" class="layui-input layui-input-inline">
                                                <input type="text" :name="'content[groupItems]['+index+'][url]'" v-model='item.url' lay-verify="required|url" placeholder="请输入链接" class="layui-input layui-input-inline">
                                                <button type="button" v-if="CGroupItems == index" @click="addGroupItem" class="layui-btn">添加一组小标题</button>
                                            </div>
                                        </div>
                                </div>
     

                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="right" id="baidu-search">
                            <div class="right-croller">
                                <link rel="stylesheet" href="/baidu/css/style.css" />
                                <div class="result c-result c-clk-recommend">
                                    <div class="c-container">
                                        <a href="" class="c-blocka">
                                            <h3 class="c-title c-title-nowrap c-gap-top-small">
                                                <span class="c-title-text" v-html="Ctitle"></span>
                                                <i class="c-text c-text-public c-gap-left-small">官网</i>
                                            </h3>
                                        </a>

                                        <div class="c-row c-gap-top-small">
                                            <div class="c-span4">
                                                <a class="c-blocka" href="" />
                                                <div class="c-img c-img-s" style="background: none;">
                                                    <img :src="thumb">
                                                </div>
                                                </a>
                                            </div>
                                            <div class="c-span8">
                                                <a class="c-blocka" :href="url">
                                                    <p class="c-line-clamp4 c-color" v-html="Cdesc"></p>
                                                </a>
                                            </div>
                                        </div>
                                        <div class="wa-www-sitelink-normal-sub">
                                            <div class="wa-www-sitelink-normal-sublist_newux c-row">
                                                <div class="c-span4" v-for="(item,index) in groupItems">
                                                    <a :href="item.url" class="c-blocka c-slink-new" v-html="item.title"></a>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="c-showurl c-line-clamp1">
                                            <a href="" class="">
                                                <span class="c-showurl" v-html="host"></span>
                                            </a>
                                            <span class="c-gap-left ec-vicon">
                                                <img class="c-icon ec-icon-blue ec-icon-size-small c-gap-right-small" src=""
                                                />
                                            </span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
<{/block}>
<{block name="script" }>
                <style type="text/css">
                    .left,
                    .right {
                        float: left;
                    }

                    .left {
                        width: 60%;
                    }

                    .right {
                        height: 550px;
                        margin-left: 60px;
                        width: 300px;
                        border: 2px solid #ccc;
                        border-radius: 20px;
                        padding: 20px;
                        background: #f1f1f1;
                        box-shadow: 1px 2px #eeeeee5c;
                    }
                    .group-item{
                        background: #f7f7f7;
                        padding: 10px 10px 10px 0;
                        border-radius: 5px;
                        margin: 10px 0;
                    }
                    .right-croller{
                        
                    }
                </style>
                <script src="/static/js/vue.js"></script>
                <script type="text/javascript">
                    var vue = new Vue({
                        el: "#app",
                        data: {
                            title: '',
                            desc: '',
                            url:'',
                            host:'m.baidu.com',
                            thumb: 'http://iph.href.lu/84x84',
                            groupItems:[
                                    {
                                        'title':'医院简介',
                                        'url':''
                                    },
                                    {
                                        'title':'医院简介',
                                        'url':''
                                    },
                                    {
                                        'title':'医院简介',
                                        'url':''
                                    }
                            ]
                        },
                        computed: {
                            Ctitle: function () {
                                if (this.title == '') {
                                    return '中国<em>移动公司</em>';
                                }
                                return this.title.replace(/{/g, '<em>').replace(/}/g, '</em>');
                            },
                            CGroupItems: function () {
                                return this.groupItems.length - 1;
                            },
                            Cdesc: function () {
                                if (this.desc == '') {
                                    return '欢迎访问<em>宝马</em>中国官方网站。BMW,悦享纯粹驾趣。... 中华慈善总会<em>宝马</em>爱心基金 企业社会责任荣誉奖项 报告下载 BMW 互联驾驶 概览 BMW 云端互联亮点 BMW 云端...';
                                }
                                return this.desc.replace(/{/g, '<em>').replace(/}/g, '</em>');
                            }

                        },
                        methods:{
                            addGroupItem:function(){
                                if (this.groupItems.length >= 12 ) {
                                    layer.msg('最多添加十二组');
                                    return;
                                }
                                this.groupItems.push({
                                    'title':'医院简介',
                                    'url':''
                                });
                            }
                        }
                    });

                    <{php}>
                        if(request()->action() == 'edit'){

                            echo "vue.Btitle = '".$data['content']['title']."';";
                            echo "vue.Bcontent = '".$data['content']['desc']."';";
                            echo "vue.Btel = '".$data['content']['tel']."';";
                            echo "vue.Burl = '".$data['content']['url']."';";
                            echo "vue.Bsrc = '".$data['content']['thumb']."';";

                            echo "vue.Bstitle1 = '".$data['content']['data']['stitle1']."';";
                            echo "vue.Bstitle2 = '".$data['content']['data']['stitle2']."';";
                            echo "vue.Bstitle3 = '".$data['content']['data']['stitle3']."';";
                            echo "vue.Bsurl1 = '".$data['content']['data']['surl1']."';";
                            echo "vue.Bsurl2 = '".$data['content']['data']['surl2']."';";
                            echo "vue.Bsurl3 = '".$data['content']['data']['surl3']."';";
                            
                        }
                    <{/php}>


                    $(function () {
                        layui.upload({
                            url: "/api/upload/upload",
                            type: 'image',
                            ext: 'jpg|png|gif|bmp',
                            success: function (data) {
                                if (data.error === 0) {
                                    document.getElementById('mythumb').value = data.url;
                                    vue.Bsrc = data.url; //映射到vue
                                    $(".c-img>img").attr('src', data.url);
                                } else {
                                    layer.msg(data.message);
                                }
                            }
                        });
                    });
                </script>
                <{/block}>